package com.crawler.store

import akka.actor.{Actor, ActorLogging}
import com.crawler.comm.CrawlerConfig
import com.crawler.service.PersistMessage
import com.crawler.utils.FileUtils
import com.typesafe.config.ConfigFactory

/**
  * Created by tongtao.zhu on 2017/3/14.
  */
class LocalStore extends Actor with ActorLogging{
  val config = ConfigFactory.load()
  val crawlerConfig = new CrawlerConfig(config)

  override def receive = {
    case persistMessage: PersistMessage =>crawler(persistMessage)
  }

  def crawler(persistMessage: PersistMessage): Unit ={
    val fileUtils = new FileUtils(s"${crawlerConfig.filePersist}/%s/%s".format(persistMessage.source, persistMessage.typ), crawlerConfig)
    fileUtils.crawlerDataStore(persistMessage)
  }
}
